home *** CD-ROM | disk | FTP | other *** search
- property pMyName : ""
- property pParameters : {maxreversals:0, maxtrials:0, stepSize:1, initialDuration:10}
- property pStairCaseRecord : {currentDuration:10, history:{-1, -1, -1}, reversals:0, directionList:{}, trialCount:0}
- --currentDuration = the variable being staircased.
- --history: a history as deep as is needed
- -- reversals: count of reversals
- --directionList: history of directions
- --valid directions = "up" "down" and "none"
- --trialCount: speaks for itself
- --assumptions: that you run the duration that it gives you
-
- to initialize(nameString, pars) --pars must be a valid parameter record, i.e., {maxreversals:5, maxtrials:3, stepSize:1, initialDuration:10}
- --try
- set pMyName to nameString
- iInitializeStairCaseRecord()
- iSetParameters(pars)
- set currentDuration of pStairCaseRecord to initialDuration of pParameters
- end initialize
-
- to update(gradedResponse) --0 if wrong, 1 if correct
- --update history and trial count
- set trialCount of pStairCaseRecord to (trialCount of pStairCaseRecord) + 1
- set gradedResponse to gradedResponse as integer
- iUpDateResponseHistory(gradedResponse)
- set last2responses to items 2 thru 3 of history of pStairCaseRecord
-
- if gradedResponse = 0 then
- iHandleShift("up") --one wrong, so shift up
- else if last2responses = {1, 1} then
- iHandleShift("down") --that's three correct in a row, so shift down
- else
- iHandleShift("none") --no shift, but update the history
- end if
- return currentDuration of pStairCaseRecord
- (* on error
- error "update failed"
- end try *)
- end update
-
- to updateStepSize(newStep)
- set stepSize of pParameters to newStep
- end updateStepSize
-
- on getRecord()
- return pStairCaseRecord
- end getRecord
-
- on getParameters()
- return pParameters
- end getParameters
-
- on getParametersAsSpreadsheetText()
- return {{pMyName & " maxreversals", maxreversals of pParameters}, ¬
- {pMyName & " maxtrials", maxtrials of pParameters}, ¬
- {pMyName & " stepSize", stepSize of pParameters}, ¬
- {pMyName & " initialDuration", initialDuration of pParameters}}
- end getParametersAsSpreadsheetText
-
-
- --be sure and synch any changes here with the getrtrialdata handler
- on getTrialDataHeaderLineAsSpreadsheetText()
- return {"stairName", "thisTrialcount", "thisDuration", "correct response", "thisSubjectResponse", "thisGradedResponse", "thisRT"}
- end getTrialDataHeaderLineAsSpreadsheetText
-
- on getTrialData(subjectResponse, correctResponse)
- tell application "PsyScript"
- if (subjectResponse = correctResponse) then
- set thisGradedResponse to 1
- else
- set thisGradedResponse to 0
- end if
- set theRt to get reaction time
- set thisTrialcount to trialCount of my getRecord()
- set thisDuration to currentDuration of pStairCaseRecord
- return {pMyName:pMyName, thisTrialcount:thisTrialcount, thisDurationt:thisDuration, correctResponse:correctResponse, subjectResponset:subjectResponse, thisGradedResponse:thisGradedResponse, thisRT:theRt}
- end tell
- end getTrialData
-
-
- on completed()
- if ((reversals of pStairCaseRecord ‚â• maxreversals of pParameters) or (trialCount of pStairCaseRecord ‚â• maxtrials of pParameters)) then
- return true
- else
- return false
- end if
- end completed
-
- --should never need to call these handlers (they start with an "i" for "internal use only"
-
-
- to iSetParameters(pars)
- set pParameters to pars
- end iSetParameters
-
-
- to iInitializeStairCaseRecord()
- set pStairCaseRecord to {currentDuration:0, history:{-1, -1, -1}, reversals:0, directionList:{}, trialCount:0}
- end iInitializeStairCaseRecord
-
- to iUpDateResponseHistory(gradedResponse)
- set beginning of history of pStairCaseRecord to gradedResponse
- end iUpDateResponseHistory
-
- to iInitializeResponseHistory()
- set history of pStairCaseRecord to {-1, -1, -1}
- end iInitializeResponseHistory
-
- to iHandleShift(direction)
- --try
- set end of directionList of pStairCaseRecord to direction
- if trialCount of pStairCaseRecord ‚â§ 2 then
- -- there is no history yet
- else if direction ≠ item -2 of directionList of pStairCaseRecord then
- set reversals of pStairCaseRecord to (reversals of pStairCaseRecord) + 1
- end if -- no need to update reversals
-
- if direction is "none" then
- --nothin but us chickens in here
- else
- if direction = "up" then
- set currentDuration of pStairCaseRecord to (currentDuration of pStairCaseRecord) + (stepSize of pParameters)
- else if direction = "down" then
- set currentDuration of pStairCaseRecord to (currentDuration of pStairCaseRecord) - (stepSize of pParameters)
- if currentDuration of pStairCaseRecord < 1 then set currentDuration of pStairCaseRecord to 1
- else
- error "direction must be up, down, or none"
- end if
- iInitializeResponseHistory()
- end if
- (* on error
- error "shiftup"
- end try *)
- end iHandleShift